<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
//  写一个加密字符串的方法
function strEncrypt(str) {
  return str.split('').map(s => {
    return String.fromCharCode(s.charCodeAt() + 1)
  }).join('')
}
console.log(strEncrypt('hello world'))


// 仅支持浏览器端：

function encode (str) {
	return btoa(encodeURIComponent(str));
}

function decode (str) {
	return decodeURIComponent(atob(str));
}
console.log(encode('hello world'));
console.log(decode('hello world'));

var str = 'i love中国';    
    // 加密
    var jiaMi = encodeURIComponent(str);    
    var jiaM = btoa(jiaMi);

    //解密，先用atob解密ascii码，然后再用decodeURIComponent
    var jieMi = atob(jiaM);
    var jieM = decodeURIComponent(jieMi);
  </script>
</body>
</html>